FROM ubuntu:22.04
RUN sed -i 's/ports.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
RUN apt update && apt upgrade
RUN apt install git maven nodejs npm vim curl wget tree zip unzip mysql-server redis-server nginx iputils-ping openjdk-17-jre -y

RUN git clone https://github.com/nvm-sh/nvm.git .nvm && cd .nvm && git checkout v0.39.1 && . ./nvm.sh && nvm install v16.17.0 && cd ~
RUN npm config set registry https://registry.npm.taobao.org

RUN mkdir -p .m2 && touch .m2/settings.xml && cat > .m2/settings.xml << EOF
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
  <pluginGroups></pluginGroups>
  <proxies></proxies>
  <servers></servers>
  <mirrors>
    <mirror>
      <id>aliyunmaven</id>
      <mirrorOf>*</mirrorOf>
      <name>aliyun repo</name>
      <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
  </mirrors>
  <profiles></profiles>
</settings>
EOF

RUN /etc/init.d/mysql start && /etc/init.d/redis start && /etc/init.d/nginx start

RUN git clone https://gitee.com/bluemiaomiao/demo-cache-db.git && cd demo-cache-db
RUN mysqladmin create db_demo -uroot && mysql -uroot db_demo < db_demo.sql

RUN cd backend && mvn clean && mvn package && cd target && nohup java -jar demo-1.0.0.jar > api-service.log &
RUN cd ../frontend && npm i && npm run build && cd dist && mv * /var/www/html && cd .. && rm -rf dist

